package com.wzl.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wzl.constant.CommonConstant;
import com.wzl.entity.dto.ContactsInfoDTO;
import com.wzl.entity.dto.PatientInfoDTO;
import com.wzl.entity.dto.TreatmentInfoDTO;
import com.wzl.service.TreatmentInfoService;
import com.wzl.util.Res;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("treatmentInfo")
@AllArgsConstructor
public class TreatmentInfoController {
    @Autowired
    private TreatmentInfoService treatmentInfoService;

    /**
     * 查询感染者治疗信息
     *
     * @param treatmentInfoDTO
     * @return Res
     */
    @PreAuthorize("@pm.hasPermission('sys:treatmentInfo:view')")
    @GetMapping("list")
    public Res list(Page<TreatmentInfoDTO> page,TreatmentInfoDTO treatmentInfoDTO) {
        return Res.success(treatmentInfoService.getPage(page, treatmentInfoDTO));
    }

    /**
     * 新增感染者治疗信息
     *
     * @param treatmentInfo
     * @return Res
     */
    @PreAuthorize("@pm.hasPermission('sys:treatmentInfo:add')")
    @PostMapping("addTreatmentInfo")
    public Res create(@RequestBody TreatmentInfoDTO treatmentInfo) {
        boolean b = this.treatmentInfoService.saveTreat(treatmentInfo);
        return b ? Res.success(b) : Res.fail(CommonConstant.DICT_FAILED);
    }

    /**
     * 修改
     *
     * @param treatmentInfo
     * @return Res
     */
    @PreAuthorize("@pm.hasPermission('sys:treatmentInfo:update')")
    @PostMapping("update")
    public Res updateTreatmentInfo(@RequestBody TreatmentInfoDTO treatmentInfo) {
        return Res.success(treatmentInfoService.updateTreatmentInfo(treatmentInfo));
    }
    /**
     * 查询密切接触者详情
     *
     * @param id
     * @return Res
     */
    @PreAuthorize("@pm.hasPermission('sys:treatmentInfo:detail')")
    @GetMapping("detail/{id}")
    public Res treatmentInfoDetail(@PathVariable("id") String id) {
        return Res.success(treatmentInfoService.treatmentInfoDetail(id));
    }
}
